package ihm;

import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import commands.Command;

/**
 * Implémentation de l'interface SensorModifierActivationImpl, basée sur la bibliothèque Swing.
 */
public class SensorModifierActivationPanelImpl extends JPanel implements SensorModifierActivationPanel {

	private static final long serialVersionUID = 6898750722281933293L;
	
	private JCheckBox isActivatedCheckBox;
	
	private Command activateSensorModifierCommand;
	private Command desactivateSensorModifierCommand;
	
	public SensorModifierActivationPanelImpl() {
		super();
		
		isActivatedCheckBox = new JCheckBox("Activer la modification automatique", true);
		this.add(isActivatedCheckBox);
		isActivatedCheckBox.addChangeListener(new SensorModifierCheckBoxChangeListener());
	}
	
	
	public void setActivateSensorModifierCommand(Command activateSensorModifierCommand) {
		this.activateSensorModifierCommand = activateSensorModifierCommand;
	}


	public void setDesactivateSensorModifierCommand(Command desactivateSensorModifierCommand) {
		this.desactivateSensorModifierCommand = desactivateSensorModifierCommand;
	}


	private class SensorModifierCheckBoxChangeListener implements ChangeListener{

		@Override
		public void stateChanged(ChangeEvent e) {
			if(isActivatedCheckBox.isSelected()) {
				activateSensorModifierCommand.execute();
			}
			else {
				desactivateSensorModifierCommand.execute();
			}
		}
		
	}

}
